/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.yutel.wuzi.game;

import com.yutel.wuzi.view.Chessboard;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

/**
 * @author yuanyajun
 */
public class Game extends MIDlet implements CommandListener {

    Display display;
    Chessboard chessboard;
    private Command exitCommand = new Command("退出", Command.EXIT, 99);
    private Command toggleCommand = new Command("开始", Command.SCREEN, 1);
    private Command helpCommand = new Command("帮助", Command.HELP, 2);
    private Form helpScreen;

    public Game() {
        display = Display.getDisplay(this);
        chessboard = new Chessboard(display);
        chessboard.addCommand(exitCommand);
        chessboard.addCommand(helpCommand);
        chessboard.setCommandListener(this);
    }

    public void startApp() {
        chessboard.start();
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }

    public void commandAction(Command c, Displayable s) {
        if (c == toggleCommand) {
            chessboard.start();
        } else if (c == helpCommand) {
            showHelp();
        } else if (c == exitCommand) {
            destroyApp(false);
            notifyDestroyed();
        }
    }

    void showHelp() {
        if (helpScreen == null) {
            helpScreen = new Form("Many Balls Help");
            helpScreen.append("----基本操作----\n");
            helpScreen.append("光标向上：2 \n");
            helpScreen.append("光标向下：8\n");
            helpScreen.append("光标向左：4\n");
            helpScreen.append("光标向右：6\n");
            helpScreen.append("确定下棋：5\n");
            helpScreen.append("----系统设置----\n");
            helpScreen.append("全    屏：#\n");
            helpScreen.append("正常屏幕：*\n");
            helpScreen.append("悔    棋：7\n");
            helpScreen.append("重新开始：9\n");
        }

        helpScreen.addCommand(toggleCommand);
        helpScreen.setCommandListener(this);
        display.setCurrent(helpScreen);
    }
}
